

// C program to count occurrences of an element 
// in a sorted array. 
# include <stdio.h> 

int count(int arr[], int x, int n) 
{     
  int *low = lower_bound(arr, arr+n, x); 
   if (low == (arr + n) || *low != x) 
     return 0; 
   int *high = upper_bound(low, arr+n, x);      
     return high - low; 
} 
int main() 
{ 
  int arr[] = {1, 2, 2, 3, 3, 3, 3}; 
  int x =  3;  // Element to be counted in arr[] 
  int n = sizeof(arr)/sizeof(arr[0]); 
  int c = count(arr, x, n); 
  printf(" %d occurs %d times ", x, c); 
  return 0; 
} 
